package cn.sylinx.horm.spring.boot;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;

import cn.sylinx.horm.spring.scan.ModelScannerRegistrar;
import cn.sylinx.horm.util.GLog;
import org.springframework.lang.NonNull;

public class AutoConfiguredModelScannerRegistrar extends ModelScannerRegistrar implements BeanFactoryAware {
	private BeanFactory beanFactory;

	@Override
	public void setBeanFactory(@NonNull BeanFactory beanFactory) throws BeansException {
		this.beanFactory = beanFactory;
	}

	@Override
	public List<String> getPackages() {
		try {
			return AutoConfigurationPackages.get(this.beanFactory);
		} catch (Exception e) {
			GLog.error("getPackages error", e);
			return Collections.singletonList("");
		}
	}
}